#ifndef VOTED_PERCEPTRON_H
#define VOTED_PERCEPTRON_H
#include "array.h"
#include "sparse.h"

typedef real (*kernel_t)(vector* x, vector* y, float p);

class perceptron{
    static kernel_t kernels[4];
    kernel_t kernel;
    float param;
    float margin;
    int bpm;
    int own;
    Array<vector*> svectors;
    Array<Array<int> > perceptrons;
    Array<Array<int> > votes;
    void shuffle(Array<vector*>& a);
    real similarity(vector* x, const Array<int>& sv, kernel_t K, float p);
    void trainlinear(Array<vector*>& trainset, int T);
    void trainnonlinear(Array<vector*>& trainset, int T);
    void testlinear(const Array<vector*>& testset, Array<real>& predv, Array<real>& preda);
    void testnonlinear(const Array<vector*>& testset, Array<real>& predv, Array<real>& preda);
public:
    perceptron();
    void set(int ktype,float p,float m,int b);
    void read(const char* file);
    void write(const char* file);
    void train(Array<vector*>& trainset, int T);
    void test(const Array<vector*>& testset, Array<real>& predv, Array<real>& preda);
    ~perceptron();
};

#endif
